package com.bluedog.listenter;

import com.bluedog.util.ColorUtils;
import net.kyori.adventure.text.Component;
import net.kyori.adventure.text.TextComponent;
import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener;
import org.bukkit.event.player.PlayerEditBookEvent;
import org.bukkit.inventory.meta.BookMeta;

import java.util.List;

public class EditBookListener implements Listener {

    @EventHandler
    public void onEditBook(PlayerEditBookEvent event) {
        BookMeta newBookMeta = event.getNewBookMeta();
        List<Component> pages = newBookMeta.pages();
        pages.replaceAll(component -> ColorUtils.getTextBuilderWithColors(((TextComponent) component).content(), "#FFFFFF").build());
        event.setNewBookMeta(newBookMeta);
    }
}
